FROM golang:1.23-alpine AS builder

WORKDIR /build

# Copy go mod files
COPY go.work go.work
COPY services/api-gateway/go.mod services/api-gateway/go.mod
COPY services/alert-service/go.mod services/alert-service/go.mod
COPY services/ai-gateway/go.mod services/ai-gateway/go.mod
COPY services/ticket-service/go.mod services/ticket-service/go.mod
COPY shared/go.mod shared/go.mod
COPY proto/go.mod proto/go.mod

# Download dependencies
RUN cd services/ticket-service && go mod download

# Copy source code
COPY services/ticket-service/ services/ticket-service/
COPY shared/ shared/
COPY proto/ proto/

# Build
RUN cd services/ticket-service && CGO_ENABLED=0 GOOS=linux go build -o /app/ticket-service ./cmd

FROM alpine:latest

RUN apk --no-cache add ca-certificates

WORKDIR /app

COPY --from=builder /app/ticket-service .

EXPOSE 50052

CMD ["./ticket-service"]
